package com.lyz.dataStructure.algorithm.腾讯面试2020;


import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/9/1 20:05
 *@Description:
 **/
/*
输入
5
7 2 4 6 5

输出
60
 */
public class 期末总结 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i =0;i<w.length;i++){
            w[i] = sc.nextInt();
        }
        System.out.println(MaxNum(w));

    }
    public static long MaxNum(int[] w){
       long chengji = 0;
        int minNum =100001;
        long sum = 0;
        // 7 2 4 6 5
        for( int i = 0;i<w.length;i++){
                int index = i;
                for(int j =0;j<index;j++){
                    minNum = minshu(w,j,index);
                    sum = sum(w,j,index);
                    chengji =Math.max(minNum*sum,chengji);
                    if(index<w.length-1){
                        index++;
                    }
                }
            }
        return chengji;
    }

    public static int sum(int[] num,int x,int y){
        int sum = 0;
        for(int i =x;i<=y;i++){
            sum+=num[i];
        }
        return sum;
    }
    public static int minshu(int[] num,int x,int y){
        int min = 100001;
        for(int i =x;i<=y;i++){
            min = Math.min(min,num[i]);
        }
        return min;
    }
}
